#include "page2.h"

static lv_ft_info_t info1;
static lv_style_t style1;

void add_pro(lv_event_t * e)
{
    page_add_show();
    lv_obj_del(page2);
}

void del_pro(lv_event_t * e)
{
    page_del_show();
    lv_obj_del(page2);
}

void cha_pro(lv_event_t * e)
{
    page_cha_show();
    lv_obj_del(page2);
}

void sea_pro(lv_event_t * e)
{
    page_sea_show();
    lv_obj_del(page2);
}

void quit(lv_event_t * e)
{
    page1_show();
    lv_obj_del(page2);
}

// 管理员界面
void page2_show()
{
    // 中文字库加载
    /*FreeType uses C standard file system, so no driver letter is required.*/
    info1.name   = "/font/simkai.ttf";
    info1.weight = 24;
    info1.style  = FT_FONT_STYLE_NORMAL;
    info1.mem    = NULL;
    if(!lv_ft_font_init(&info1)) {
        LV_LOG_ERROR("create failed.");
    }
    /*Create style with the new font*/
    lv_style_init(&style1);
    lv_style_set_text_font(&style1, info1.font);
    lv_style_set_text_align(&style1, LV_TEXT_ALIGN_CENTER);

    // 新建页面1
    show_page(&page2);

    // 增加商品按钮
    lv_obj_t * btn1 = show_btn_label(page2, 200, 80, 180, 20, &style1, "增加商品");
    lv_obj_add_event_cb(btn1, add_pro, LV_EVENT_CLICKED, NULL);

    // 删除商品按钮
    lv_obj_t * btn2 = show_btn_label(page2, 200, 80, 420, 20, &style1, "删除商品");
    lv_obj_add_event_cb(btn2, del_pro, LV_EVENT_CLICKED, NULL);

    // 更改商品按钮
    lv_obj_t * btn3 = show_btn_label(page2, 200, 80, 180, 120, &style1, "更改商品");
    lv_obj_add_event_cb(btn3, cha_pro, LV_EVENT_CLICKED, NULL);

    // 搜寻商品按钮
    lv_obj_t * btn4 = show_btn_label(page2, 200, 80, 420, 120, &style1, "搜寻商品");
    lv_obj_add_event_cb(btn4, sea_pro, LV_EVENT_CLICKED, NULL);

    // 返回购买界面
    lv_obj_t * btn5 = show_btn_label(page2, 80, 80, 10, 20, &style1, "返回");
    lv_obj_add_event_cb(btn5, quit, LV_EVENT_CLICKED, NULL);
}